/*
 * Created on 20 ao�t 2005
 *
 */

package picoevo.gp.evolution;

import picoevo.core.evolution.VariationOperator;
import picoevo.core.representation.EvolutionObject;
import picoevo.core.representation.Population;
import picoevo.gp.representation.genericoperators.Element_Node_TreeGP_FunctionCall;

public class VariationOperator_Element_TreeGP_FunctionIndexMutation extends VariationOperator {

	public VariationOperator_Element_TreeGP_FunctionIndexMutation(String __name) {
		super(__name);
	}

	VariationOperator_Element_TreeGP_FunctionIndexMutation(String __name, double __operatorRate) {
		super(__name, __operatorRate);
	}

	@Override
	public void applyOperator(EvolutionObject __element) {
		Element_Node_TreeGP_FunctionCall element = (Element_Node_TreeGP_FunctionCall) __element;
		if (Math.random() < (element.getTemplate()).getDoubleProperty("FunctionIndexMutationRate")) {
			// String oldvalue = element.getDisplayValue();
			int newValue = (int) (Math.random() * (((Population) element.getTemplate().getObjectProperty("ModulePopulation")).getPopulationSize()));
			element.setFunctionIndex(newValue);
			// Display.debug("MUTE_FUNC("+oldvalue+"->"+newValue+")");
		}
	}
}
